package com.xsq.netty;

import com.xsq.netty.utils.NettyMsgUtil;

/**
 * Created by Shiquan.Xiao on 2023/10/17.
 */
public class NettyConfig {

    public boolean isOpenLog = false;
    public String heartbeatMsg;
    public boolean isNeedInitConnect;
    public String[] connectedMsg;
    public String servicePackageName;
    public String host = "";
    public String deviceAddress;
    public int port;
    public int connectedSendDelayed;
    // 连接超时时长
    public int connectTimeout = 10 * 1000;
    // 默认重连一个周期失败间隔时长
    public int reconnectInterval = 3 * 1000;
    // 心跳间隔时间
    public int heartbeatInterval = 60 * 1000;
    // 服务器没响应间隔时间
    public int severOnResponseInterval = 2 * 60 * 1000;
    public boolean isService;
    public boolean isAutoConnect;
    public boolean isConnectedSendIp;
    public boolean isEstablishConnectionSend;

    public static class Builder {
        private final NettyConfig nettyConfig;
        public Builder() {
            nettyConfig = new NettyConfig();
        }

        public Builder setOpenLog(boolean isOpenLog) {
            nettyConfig.isOpenLog = isOpenLog;
            return this;
        }

        public Builder setServicePackageName(String packageName) {
            nettyConfig.servicePackageName = packageName;
            return this;
        }

        public Builder setHost(String host) {
            nettyConfig.host = host;
            return this;
        }

        public Builder setDeviceAddress(String deviceAddress) {
            nettyConfig.deviceAddress = deviceAddress;
            nettyConfig.heartbeatMsg = NettyMsgUtil.getMsg(deviceAddress, NettyHelper.HEART_BEAT, "").toString();
            return this;
        }

        public Builder setPort(int port) {
            nettyConfig.port = port;
            return this;
        }

        public Builder setIsAutoConnect(boolean isAutoConnect) {
            nettyConfig.isAutoConnect = isAutoConnect;
            return this;
        }

        public Builder setConnectedSendIp(boolean connectedSendIp) {
            nettyConfig.isConnectedSendIp = connectedSendIp;
            return this;
        }

        public Builder setIsService(boolean service) {
            nettyConfig.isService = service;
            return this;
        }

        public Builder setHeartbeatMsg(String heartbeatMsg) {
            nettyConfig.heartbeatMsg = heartbeatMsg;
            return this;
        }

        public Builder setConnectedMsg(String[] connectedMsg) {
            nettyConfig.connectedMsg = connectedMsg;
            return this;
        }

        public Builder setNeedInitConnect(boolean isNeedInitConnect) {
            nettyConfig.isNeedInitConnect = isNeedInitConnect;
            return this;
        }

        public Builder setEstablishConnectionSend(boolean establishConnectionSend) {
            nettyConfig.isEstablishConnectionSend = establishConnectionSend;
            return this;
        }
        public Builder setConnectedSendDelayed(int connectedSendDelayed) {
            nettyConfig.connectedSendDelayed = connectedSendDelayed;
            return this;
        }

        public Builder setConnectTimeout(int connectTimeout) {
            nettyConfig.connectTimeout = connectTimeout;
            return this;
        }

        public Builder setReconnectInterval(int reconnectInterval) {
            nettyConfig.reconnectInterval = reconnectInterval;
            return this;
        }

        public Builder setHeartbeatInterval(int heartbeatInterval) {
            nettyConfig.heartbeatInterval = heartbeatInterval;
            return this;
        }

        public Builder setSeverOnResponseInterval(int severOnResponseInterval) {
            nettyConfig.severOnResponseInterval = severOnResponseInterval;
            return this;
        }

        public NettyConfig build() {
            return nettyConfig;
        }
    }

}
